/* Author: Mark Mckillion
 * Student ID: B00540772
 * Date: 07/03/2012
 * Version 1.0.*/
package assignment3;

public class BankAccount
{   /*This class will be used to create BankAccounts. BankAccounts will record
     *the balance and allow the user to add and remove amounts from that.*/
    
    //declare the balance integer.
    private int accountBalance;
    
    //create the constructor and set the inital balance as 0.
    public BankAccount()
    {   accountBalance = 0;
    }
    
    /*create methods to allow the user to add or remove funds from the account.
     *The methods needs to be synchronized to lock the information while processing.*/
    public synchronized void deposit(int addAmount, String name)
    {   /*two parameters addAmount will be the amount to be deposited and name
         * is the type deposit.*/
        accountBalance+=addAmount; // add the amount to the balance.
        
        //print out information to inform the user of the deposit.
        System.out.println(name + " added " + addAmount);
        System.out.println("Current Balance = " + accountBalance);
        System.out.println("");
    }
    
    public synchronized void withdraw(int takeAmount, String name)
    {   /*two parameters takeAmount will be the amount to be withdrawn and name
         * is the type withdrawl.*/
        accountBalance-=takeAmount;
        
        //print out information to inform the user of the withdrawl.
        System.out.println(name + " withdrawn " + takeAmount);
        System.out.println("Current Balance = " + accountBalance);
        System.out.println("");
    }
    
    public synchronized int getBalance()
    {   //this method will return the balance.
        return accountBalance;
    }
} // End of class BankAccount